package shuaige.jdk.集合;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;

public class String和List相互转换 {
    public static void main(String[] args) {
        List转String数组();
    }

    public static void String转List() {
        //常见的为逗号分隔
        String str = "a,b,c";
        List<String> list1 = Arrays.asList(str.split(",")); //[a, b, c]
        for (String s : list1) {
            System.out.println(s);
        }
    }

    public static void List转String() {
        List<String> list = new ArrayList<>();
        list.add("a");
        list.add("b");
        list.add("c");
        // a,b,c
        String str2 = String.join(",", list);
        System.out.println(str2);
    }


    public static void List转String数组() {
        List<String> list = new ArrayList<>();
        list.add("a");
        list.add("b");
        list.add("c");
        // a,b,c
        String[] split = String.join(",", list)
                .split(",");
        System.out.println(split);
    }


}
